using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Drawing.Imaging;
using System.Drawing;

namespace LabyrinthProject
{
    class Cupavci : IDrawable
    {
        #region fields
        private Labyrinth labyrinth;
        private Matrix world;
        private Model model;

        private Vector3 position;
        private Vector2 direction;
        private float height;

        public BoundingBox box;
        #endregion
        #region properties
        public Model Model
        {
            get { return model; }
            set { model = value; }
        }

        public Vector3 Position
        {
            get { return new Vector3(position.X, height, position.Y) * 1000; }
            set { position = new Vector3(value.X, value.Y, value.Z); }
        }
        #endregion
        #region intialization
        public Cupavci(Model model, Labyrinth labyrinth, Vector3 position)
        {
            this.labyrinth = labyrinth;
            this.model = model;

            this.position = position;
        }
        #endregion
        #region methods
        public void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;            
        }

        public void Draw(Camera camera)
        {
            box = new BoundingBox(position - new Vector3(300, 0, 300), position + new Vector3(300, 500, 300));

            world = Matrix.Identity;
            world.Translation = position;
            Matrix scale = Matrix.CreateScale(20);
            Matrix rotation = Matrix.CreateRotationY(3* (float) Math.PI / 2);
            world = scale * rotation * world;
            

            LabyrinthGame.GDevice.Viewport = camera.Viewport;

            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            LabyrinthGame.GDevice.BlendState = BlendState.NonPremultiplied;
            LabyrinthGame.GDevice.DepthStencilState = DepthStencilState.Default;


            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * world;
                    // Use the matrices provided by the chase camera
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                    effect.Alpha = 1f;
                }
                mesh.Draw();
            }
        }
        #endregion
    }
}
